package com.aaa.ssm.service.impl;

import com.aaa.ssm.mapper.StudentMapper;
import com.aaa.ssm.pojo.dto.StudentDTO;
import com.aaa.ssm.pojo.dto.StudentVO;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.service.StudentService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;

    @Override
    public Map<String, Object> listAllStudent(StudentQuery query) {
        List<StudentDTO> studentDTOS = studentMapper.searchStudents(query);
        Integer i = studentMapper.studentCount(query);
        HashMap<String, Object> map=new HashMap<>();
        map.put("currentData",studentDTOS);
        map.put("studentstotal",i);
        return map;
    }

    @Override
    public Integer deleteStudent(Integer id) {
        Integer i = studentMapper.deleteStudentByID(id);
        return i;
    }

    @Override
    public int addStudent(StudentDTO studentDTO) {
        int student = studentMapper.addStudent(studentDTO);
        return student;
    }

    @Override
    public Integer updateStuByteID(StudentVO studentDTO) {
        System.out.println(studentDTO);
        return studentMapper.updateByteID(studentDTO);
    }



    @Override
    public StudentDTO getStuByteID(Integer id) {
        return studentMapper.getStuByteID(id);
    }
}
